from boot import QVBoxLayout, QFrame, QWidget, Union, Qt
from view.widget.qq9_content_logo import QQ9ContentLogo
from view.widget.qq9_button import QQ9PushButton, QQ9PrimaryPushButton
from view.widget.qq9_layout_widget import QQ9HLayoutWidget


__all__ = ["ContentFrameBase", "init_tool_button"]


def init_tool_button(cls):
    def wrapper(self, *args, **kwargs):
        obj = cls(self, *args, **kwargs)

        # 按钮布局
        self.button_widget = QQ9HLayoutWidget()
        self.button_widget.setFixedHeight(120)
        self.content_frame.main_v_layout.addWidget(self.button_widget)

        # 编辑按钮
        self.edit_button = QQ9PushButton(text="编辑")
        self.edit_button.setFixedSize(135, 30)
        self.button_widget.add_widget(self.edit_button)

        # 删除按钮
        self.delete_button = QQ9PrimaryPushButton(text="删除")
        self.delete_button.setFixedSize(135, 30)
        self.button_widget.add_widget(self.delete_button)

        # 初始化无内容
        self.set_no_content()
        return obj
    return wrapper


class ContentFrameBase(QFrame):
    def __init__(self, parent: Union[QWidget, None] = None):
        super().__init__(parent=parent)

        self.first_scan = True

        self.main_v_layout = QVBoxLayout()
        self.main_v_layout.setContentsMargins(0, 0, 0, 0)
        self.main_v_layout.setSpacing(0)
        self.main_v_layout.setAlignment(Qt.AlignCenter)
        self.setLayout(self.main_v_layout)

        # 内容页面logo
        self.content_logo = QQ9ContentLogo()
        self.main_v_layout.addWidget(self.content_logo)

        # 内容页面
        self.content_frame = ContentFrame()
        self.main_v_layout.addWidget(self.content_frame, stretch=1)

    def set_no_content(self):
        if self.first_scan:
            self.content_frame.setHidden(True)
            self.content_logo.setHidden(False)
            self.first_scan = False

    def set_yes_content(self):
        if not self.first_scan:
            self.content_logo.setHidden(True)
            self.content_frame.setHidden(False)
            self.first_scan = True


class ContentFrame(QFrame):

    def __init__(self, parent: Union[QWidget, None] = None):
        super().__init__(parent=parent)

        self.setFixedWidth(500)

        self.main_v_layout = QVBoxLayout()
        self.main_v_layout.setContentsMargins(0, 120, 0, 0)
        self.main_v_layout.setSpacing(0)
        self.main_v_layout.setAlignment(Qt.AlignTop)
        self.setLayout(self.main_v_layout)